package com.hx.office.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hx.common.annotation.Log;
import com.hx.common.core.controller.BaseController;
import com.hx.common.core.domain.AjaxResult;
import com.hx.common.enums.BusinessType;
import com.hx.office.domain.AttendanceTime;
import com.hx.office.service.IAttendanceTimeService;
import com.hx.common.utils.poi.ExcelUtil;
import com.hx.common.core.page.TableDataInfo;

/**
 * 规定的考勤时间Controller
 * 
 * @author lidelong
 * @date 2023-05-18
 */
@RestController
@RequestMapping("/time")
public class AttendanceTimeController extends BaseController
{
    @Autowired
    private IAttendanceTimeService attendanceTimeService;

    /**
     * 查询规定的考勤时间列表
     */
    @PreAuthorize("@ss.hasPermi('office:time:list')")
    @GetMapping("/list")
    public TableDataInfo list(AttendanceTime attendanceTime)
    {
        startPage();
        List<AttendanceTime> list = attendanceTimeService.selectAttendanceTimeList(attendanceTime);
        return getDataTable(list);
    }

    /**
     * 导出规定的考勤时间列表
     */
    @PreAuthorize("@ss.hasPermi('office:time:export')")
    @Log(title = "规定的考勤时间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AttendanceTime attendanceTime)
    {
        List<AttendanceTime> list = attendanceTimeService.selectAttendanceTimeList(attendanceTime);
        ExcelUtil<AttendanceTime> util = new ExcelUtil<AttendanceTime>(AttendanceTime.class);
        util.exportExcel(response, list, "规定的考勤时间数据");
    }

    /**
     * 获取规定的考勤时间详细信息
     */
    @PreAuthorize("@ss.hasPermi('office:time:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(attendanceTimeService.selectAttendanceTimeById(id));
    }

    /**
     * 新增规定的考勤时间
     */
    @PreAuthorize("@ss.hasPermi('office:time:add')")
    @Log(title = "规定的考勤时间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AttendanceTime attendanceTime)
    {
        return toAjax(attendanceTimeService.insertAttendanceTime(attendanceTime));
    }

    /**
     * 修改规定的考勤时间
     */
    @PreAuthorize("@ss.hasPermi('office:time:edit')")
    @Log(title = "规定的考勤时间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AttendanceTime attendanceTime)
    {
        return toAjax(attendanceTimeService.updateAttendanceTime(attendanceTime));
    }

    /**
     * 删除规定的考勤时间
     */
    @PreAuthorize("@ss.hasPermi('office:time:remove')")
    @Log(title = "规定的考勤时间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(attendanceTimeService.deleteAttendanceTimeByIds(ids));
    }
}
